<!-- 查看家长详情信息 -->
<template>
  <el-dialog v-model="dialogVisible" title="查看家长详情信息" width="50%" @close="closeDialog">
    <el-form :model="familyModel" label-width="100px" style="padding-right: 30px">
      <el-form-item label="姓名：">
        <el-input v-model="familyModel.studentList" disabled>家长</el-input>
      </el-form-item>
      <el-form-item label="身份证号：" prop="parentCardId">
        <el-input v-model="familyModel.parentCardId" disabled></el-input>
      </el-form-item>
      <el-form-item label="手机号：" prop="phone">
        <el-input v-model="familyModel.phone" disabled></el-input>
      </el-form-item>
      <el-form-item label="学生：" prop="studentList">
        <el-input v-model="familyModel.studentList" disabled></el-input>
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="familyModel.password" disabled></el-input>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import { getFamilyDetail } from "@/api/family/index";
import { getStudentList } from "@/api/student/index";

const dialogVisible = ref(false);

const familyModel = reactive({
  id: 0,
  phone: "",
  parentCardId: "",
  password: "",
  studentList: [],
});

const open = (row: any) => {
  dialogVisible.value = true;
  familyModel.id = row.id;
  getInfo();
};

// 获取家长信息
const getInfo = async () => {
  const { data } = await getFamilyDetail(familyModel.id);
  Object.assign(familyModel, data);
  getstudentName();
};

//学生姓名
const getstudentName = async () => {
  const { data } = await getStudentList(familyModel.id);
  // console.log(data);
  familyModel.studentList = data.map((item: any) => item.name).join(",");
};

const closeDialog = () => {
  dialogVisible.value = false;
};
defineExpose({ open, close });
</script>
